"use strict";
cc._RF.push(module, 'ce8b97sAJtD86GzWt4CKlwk', 'KingController');
// scripts/KingController.js

"use strict";

var e = require;
var t = module;
var n = i(e("RecorderPanel")),
    o = i(e("SoundMgr"));

function i(e) {
  return e && e.__esModule ? e : {
    "default": e
  };
}

window.KingController = {
  Instance: null
};
var a = e("LevelManager"),
    r = e("DeathController"),
    s = null;
cc.Class({
  "extends": cc.Component,
  properties: {
    AllowKingAgeChange: {
      type: Boolean,
      "default": !0
    },
    DeathController: r,
    ControllerAnimation: dragonBones.ArmatureDisplay,
    ControllerDrinkHand: cc.Node,
    ControllerHeadAgeSprite: {
      type: cc.Sprite,
      "default": null
    },
    ControllerHeadAgeSpriteFrames: {
      type: [cc.SpriteFrame],
      "default": []
    }
  },
  onLoad: function onLoad() {
    KingController.Instance = this;
  },
  start: function start() {
    CameraManager.Instance.CameraTarget = this.node;
    LevelManager.Instance.GameCurrentOperationMode = a.GameOperationMode.Defense;
    LevelManager.Instance.GameAllowOperation = !0;
    LevelManager.Instance.KingBackHeadSpriteNode.active = !0;
    this.ControllerAnimation.addEventListener(dragonBones.EventObject.COMPLETE, function () {
      "oldDeath" == this.ControllerAnimation.animationName && this.OldDeath();
    }.bind(this), this);
  },
  onDestroy: function onDestroy() {
    KingController.Instance = null;
  },
  update: function update(e) {
    n["default"].GamePause || LevelManager.Instance.AllowAvatarControllerMove && (this.node.x += LevelManager.Instance.AvatarControllerMoveSpeed * e);
  },
  lateUpdate: function lateUpdate() {
    if (this.AllowKingAgeChange) {
      var e = LevelManager.Instance.HealthProgressBar.progress;
      e > .92 && e <= 1 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[0] : e > .85 && e <= .92 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[1] : e > .78 && e <= .85 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[2] : e > .72 && e <= .78 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[3] : e > .68 && e <= .72 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[4] : e > .63 && e <= .68 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[5] : e > .58 && e <= .63 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[6] : e > .55 && e <= .58 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[7] : e > .52 && e <= .55 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[8] : e > .48 && e <= .52 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[9] : e > .45 && e <= .48 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[10] : e > .4 && e <= .45 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[11] : e > .34 && e <= .4 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[12] : e > .28 && e <= .34 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[13] : e > .22 && e <= .28 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[14] : e > .16 && e <= .22 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[15] : e > .1 && e <= .16 ? this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[16] : e > 0 && e <= .1 && (this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[17]);
    }
  },
  LeftLookDiscover: function LeftLookDiscover() {
    if (!(this.node.position.sub(NPCKillerController.Instance.node.position).mag() >= LevelManager.Instance.AvatarControllerDistanceMinLimit)) {
      LevelManager.Instance.AllowAvatarControllerMove = !1;
      this.ControllerAnimation.playAnimation("back", 1);
      o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[7]);
      LevelManager.Instance.KingBackHeadSpriteNode.active = !1;
      this.unschedule(s);

      s = function s() {
        this.LeftLookDiscoverOver();
      };

      this.scheduleOnce(s, LevelManager.Instance.AllowKingLeftLookTime);
      NPCKillerController.Instance.onKingDiscoverFunction();
    }
  },
  LeftLookDiscoverOver: function LeftLookDiscoverOver() {
    if (LevelManager.Instance.GameCurrentOperationScene != a.GameSceneBlockType.Jail) {
      LevelManager.Instance.KingBackHeadSpriteNode.active = !0;
      this.unschedule(s);
      LevelManager.Instance.AllowAvatarControllerMove = !0;
      LevelManager.Instance.PointerIsDown = !1;
      this.ControllerAnimation.playAnimation("walk", 0);
      NPCKillerController.Instance.onKingDiscoverFunctionOver();
    }
  },
  Death: function Death(e, t) {
    void 0 === t && (t = !1);
    LevelManager.Instance.KingBackHeadSpriteNode.active = !1;
    var n = 0,
        o = LevelManager.Instance.HealthProgressBar.progress;
    o > .7 && o <= 1 ? n = 0 : o > .5 && o <= .7 ? n = 1 : o > .2 && o <= .5 ? n = 2 : o > 0 && o <= .2 && (n = 3);
    this.DeathController.DeathFunction(e, t, n);
    this.node.destroy();
  },
  OldDeath: function OldDeath() {
    ColourBackground.Instance.Show();
    o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[10]);
    LevelManager.Instance.KingBackHeadSpriteNode.active = !1;
    var e = this;
    this.scheduleOnce(function () {
      e.DeathController.DeathFunction(-1, !1, 3);

      switch (NPCKillerController.Instance.ControllerType) {
        case a.AvatarControllerType.YellowKiller:
          (t = cc.instantiate(AssetManager.Instance.KingControllerPrefabs[3])).parent = LevelManager.Instance.SceneContentNode;
          t.position = e.node.position;
          break;

        case a.AvatarControllerType.GreenDrinkSteward:
          (t = cc.instantiate(AssetManager.Instance.KingControllerPrefabs[5])).parent = LevelManager.Instance.SceneContentNode;
          t.position = e.node.position;
          break;

        default:
          var t;
          (t = cc.instantiate(AssetManager.Instance.KingControllerPrefabs[3])).parent = LevelManager.Instance.SceneContentNode;
          t.position = e.node.position;
      }

      var n = cc.instantiate(AssetManager.Instance.ControllerPrefabs[2]);
      n.parent = LevelManager.Instance.SceneContentNode;
      n.position = cc.v2(e.node.x - 1500, e.node.y);
      NPCKillerController.Instance.node.destroy();
      LevelManager.Instance.GameAllowOperation = !0;
      LevelManager.Instance.AllowAvatarControllerMove = !0;
      e.node.destroy();
    }, 1);
  },
  DrinkRedWine: function DrinkRedWine() {
    this.AllowKingAgeChange = !1;
    LevelManager.Instance.GameAllowOperation = !1;
    LevelManager.Instance.AllowAvatarControllerMove = !1;
    this.ControllerAnimation.playAnimation("drunk", 1);
    this.scheduleOnce(function () {
      ColourBackground.Instance.Show(cc.color(255, 255, 128));
      this.scheduleOnce(function () {
        this.ControllerAnimation.playAnimation("walk", 0);
        LevelManager.Instance.HealthProgressBar.node.active = !1;
        this.ControllerHeadAgeSprite.spriteFrame = this.ControllerHeadAgeSpriteFrames[0];
        NPCKillerController.Instance.AllowCurrentControllerMove = !1;
        NPCKillerController.Instance.ControllerMHandRoot && (NPCKillerController.Instance.ControllerMHandRoot.angle = NPCKillerController.Instance.DefaultMHandAngle);
        NPCKillerController.Instance.ControllerHeadSprite && (NPCKillerController.Instance.ControllerHeadSprite.spriteFrame = NPCKillerController.Instance.HeadLevelSpriteFrames[0]);
        NPCKillerController.Instance.ControllerAnimation.playAnimation("walk", 0);
        LevelManager.Instance.AllowAvatarControllerMove = !0;
        this.ControllerDrinkHand.active = !1;
        this.scheduleOnce(function () {
          NPCKillerController.Instance.destroy();
        }, 4.5);
        this.scheduleOnce(function () {
          LevelManager.Instance.CreateRandomNPCKiller();
          LevelManager.Instance.GameAllowOperation = !0;
        }, 5);
      }, 1);
    }, 3.2);
  },
  DrinkGreenWine: function DrinkGreenWine() {
    LevelManager.Instance.GameAllowOperation = !1;
    LevelManager.Instance.AllowAvatarControllerMove = !1;
    this.ControllerAnimation.playAnimation("drunk", 1);
    this.scheduleOnce(function () {
      ColourBackground.Instance.Show();
      this.scheduleOnce(function () {
        this.Death(a.AvatarControllerType.GreenDrinkSteward);
        var e = cc.instantiate(AssetManager.Instance.KingControllerPrefabs[a.AvatarControllerType.GreenDrinkSteward]);
        e.parent = LevelManager.Instance.SceneContentNode;
        e.position = KingController.Instance.node.position;
        var t = cc.instantiate(AssetManager.Instance.ControllerPrefabs[2]);
        t.parent = LevelManager.Instance.SceneContentNode;
        t.position = cc.v2(this.node.x - 700, this.node.y);
        NPCKillerController.Instance.node.destroy();
        LevelManager.Instance.GameAllowOperation = !0;
        LevelManager.Instance.AllowAvatarControllerMove = !0;
      }, 1);
    }, 3.2);
  },
  onJailSceneFinish: function onJailSceneFinish() {
    this.LeftLookDiscoverOver();
  }
});

cc._RF.pop();